package game.metalmax.ui
{
	import game.metalmax.animation.zone.SceneZone;
	import game.metalmax.controller.Notifications;
	
	import showtime.framework.engine.World2D;
	import showtime.framework.mvc.interfaces.INotification;
	import showtime.framework.mvc.patterns.mediator.Mediator;
	
	public class CanvasMediator extends Mediator
	{	
		private var parent:Object = null;
		
		public function CanvasMediator(parent:Object)
		{
			super(String(CanvasMediator));
			
			this.parent = parent;
		}
		
		override public function onRegister():void
		{
			super.onRegister();			
	
			viewComponent = new Canvas();			
			parent.addChild(viewComponent);

		}
		
		override public function onRemove():void
		{
			super.onRemove();
		}
		
		override public function listNotificationInterests():Array
		{
			return [Notifications.ENTER_SCENE, Notifications.DEACTIVATE_ZONE, Notifications.ACTIVE_ZONE];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			switch (notification.getName())
			{
				case Notifications.ENTER_SCENE:
				{
					enterScene();
					break;
				}
				case Notifications.DEACTIVATE_ZONE:
				{
					deactiveZone();
					break;
				}
				case Notifications.ACTIVE_ZONE:
				{
					activeZone();
					break;
				}
			}
		}
		
		private function enterScene():void
		{
			World2D.switchScene(new SceneZone());			
		}
		
		private function deactiveZone():void
		{
			if (World2D.scene != null)
			{
				SceneZone(World2D.scene).active = false;	
			}
			
		}
		
		private function activeZone():void
		{
			if (World2D.scene != null)
			{
				SceneZone(World2D.scene).active  = true;	
			}
			
		}

	}
}